<?php
namespace app\wechat\controller;


use think\View;

class RComment extends Common
{
    // 评论页面
    public function index() {

        // 获取标签数据
        $repair_id = input('param.id');
        $this->assign('repair_id', $repair_id);

        $where['type'] = 2;  //服务订单
        $where['merchant_id'] = $repair_id;  // 维修店ID
        $comment_ids = db('comment')->where($where)->column('id');
        $labels = db('comment_order_label')->field('label, count(id) num')->where('comment_id', 'in', implode(',', $comment_ids))->group('label')->select();
        $this->assign('labels', $labels);

        $level = db('comment')->where($where)->avg('level');
        $this->assign('level', ceil($level));

        $num = db('comment')->where($where)->count();
        $this->assign('num', $num);

        return view();
    }

    // 获取评论列表
    public function get_list() {
        if (request()->isAjax()) {
            // 获取标签数据
            $repair_id = input('param.repair_id');
            $param['type'] = 2;
            $param['merchant_id'] = $repair_id;
            $data = call_interface('get_comment_list',$param);
            $view = new View();
            $view->assign('data', $data["data"]["data"]);

            $tpl = $view->fetch('r_comment/list_tpl');
            //$data = $data->toArray();
            $data['tpl'] = $tpl;
            return json($data);
        }
        return view('base/error');
    }
}
